package com.eshop.config;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModel;
import org.springframework.context.annotation.Bean;
import com.google.common.collect.Lists;
import springfox.documentation.schema.AlternateTypeRules;
import java.lang.reflect.Type;
import org.springframework.data.domain.Pageable;
import springfox.documentation.schema.AlternateTypeRule;
import java.util.List;
import springfox.documentation.schema.AlternateTypeRuleConvention;
import com.fasterxml.classmate.TypeResolver;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import org.springframework.context.annotation.Import;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableSwagger2
@EnableKnife4j
@Import({ BeanValidatorPluginsConfiguration.class })
class SwaggerDataConfig
{
    @Bean
    public AlternateTypeRuleConvention pageableConvention(final TypeResolver resolver) {
        return (AlternateTypeRuleConvention)new AlternateTypeRuleConvention() {
            public int getOrder() {
                return Integer.MIN_VALUE;
            }
            
            public List<AlternateTypeRule> rules() {
                return Lists.newArrayList(new AlternateTypeRule[]{
                                AlternateTypeRules.newRule(resolver.resolve(Pageable.class, new Type[0]),
                                        resolver.resolve(Page.class, new Type[0]))
                        });
            }
        };
    }
    
    @ApiModel
    private static class Page
    {
        @ApiModelProperty("页码 (0..N)")
        private Integer page;
        @ApiModelProperty("每页显示的数目")
        private Integer size;
        @ApiModelProperty("以下列格式排序标准：property[,asc | desc]。 默认排序顺序为升序。 支持多种排序条件：如：id,asc")
        private List<String> sort;
        
        public Page() {
        }
        
        public Integer getPage() {
            return this.page;
        }
        
        public Integer getSize() {
            return this.size;
        }
        
        public List<String> getSort() {
            return this.sort;
        }
        
        public void setPage(final Integer page) {
            this.page = page;
        }
        
        public void setSize(final Integer size) {
            this.size = size;
        }
        
        public void setSort(final List<String> sort) {
            this.sort = sort;
        }
        
        @Override
        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            }
            if (!(o instanceof Page)) {
                return false;
            }
            final Page other = (Page)o;
            if (!other.canEqual(this)) {
                return false;
            }
            final Object this$page = this.getPage();
            final Object other$page = other.getPage();
            Label_0065: {
                if (this$page == null) {
                    if (other$page == null) {
                        break Label_0065;
                    }
                }
                else if (this$page.equals(other$page)) {
                    break Label_0065;
                }
                return false;
            }
            final Object this$size = this.getSize();
            final Object other$size = other.getSize();
            Label_0102: {
                if (this$size == null) {
                    if (other$size == null) {
                        break Label_0102;
                    }
                }
                else if (this$size.equals(other$size)) {
                    break Label_0102;
                }
                return false;
            }
            final Object this$sort = this.getSort();
            final Object other$sort = other.getSort();
            if (this$sort == null) {
                if (other$sort == null) {
                    return true;
                }
            }
            else if (this$sort.equals(other$sort)) {
                return true;
            }
            return false;
        }
        
        protected boolean canEqual(final Object other) {
            return other instanceof Page;
        }
        
        @Override
        public int hashCode() {
            final int PRIME = 59;
            int result = 1;
            final Object $page = this.getPage();
            result = result * 59 + (($page == null) ? 43 : $page.hashCode());
            final Object $size = this.getSize();
            result = result * 59 + (($size == null) ? 43 : $size.hashCode());
            final Object $sort = this.getSort();
            result = result * 59 + (($sort == null) ? 43 : $sort.hashCode());
            return result;
        }
        
        @Override
        public String toString() {
            return "SwaggerDataConfig.Page(page=" + this.getPage() + ", size=" + this.getSize() + ", sort=" + this.getSort() + ")";
        }
    }
}
